package com.itheima.sync.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.Brand;
import com.itheima.sync.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping()
    public Result findAll() {
        return this.brandService.findAll();
    }

    @PostMapping()
    public Result add(@RequestBody Brand brand) {
        return this.brandService.add(brand);

    }

    @PostMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable(value = "page") Integer page, @PathVariable(value = "size") Integer size) {
        return this.brandService.findPage(page, size);
    }

    @GetMapping("/find/{id}")
    public Result findById(@PathVariable Integer id) {
        return this.brandService.findById(id);
    }

    @PutMapping("/{id}")
    public Result update(@PathVariable(value = "id") Integer id,@RequestBody Brand brand) {

        return this.brandService.update(id,brand);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(value = "id") Integer id) {

        return this.brandService.delete(id);
    }


}